package org.qfedu.framwork.autoconfig;

import org.qfedu.framwork.service.NetworkService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xiaobobo
 * @title: NetworkServiceAutoConfiguration
 * @projectName CD-Java-FY-2401-Springboot-Parent
 * @description: 这个就是自动配置的类
 * @date 2024/9/10  9:31
 */
@Configuration
@ConditionalOnClass(value = NetworkService.class) //在类路径下必须要有这个类存在的时候才使能
@EnableConfigurationProperties(NetworkServiceProperties.class) //将属性配置文件引进来
public class NetworkServiceAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public NetworkService networkService(NetworkServiceProperties networkServiceProperties){
        return new NetworkService(networkServiceProperties.getHost(),networkServiceProperties.getPort());
    }

}
